<div class="box box-solid no-margin box-show">
    <div class="box-body">
        <h4>基本信息</h4>
        <div class="box-body table-responsive no-padding">
            <table class="table">
                <thead>
                <tr>
                    <th width="10%">发货单号</th>
                    <th>销售员</th>
                    <th>发货站点</th>
                    <th>发货仓库</th>
                    <th>发货时间</th>
                    <th>状态</th>
                    <th>运输状态</th>
                    <th>是否标贴</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>{{ $delivery->delivery_no }}</td>
                    <td>{{ \App\Util\User::getUsernameById($delivery->seller_id) }}</td>
                    <td>{{ $delivery->area->area ?? '' }}</td>
                    <td>{{ $delivery->warehouse->w_code ?? '' }}</td>
                    <td>{{ $delivery->delivered_at ?? '' }}</td>
                    <td>{{ \App\Models\OverSeasIn\Delivery::$_status[$delivery->status] }}</td>
                    <td>{{ \App\Models\OverSeasIn\Delivery::$_transportStatus[$delivery->transport_status] }}</td>
                    <td>{{ \App\Models\OverSeasIn\Delivery::$_isFnsku[$delivery->is_fnsku] }}</td>
                </tr>
                </tbody>
            </table>
            <table class="table">
                <thead>
                <tr>
                    <th>批次号</th>
                    <th>备注</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>
                        @if($delivery->status < 5)
                            <a class="grid-editable-batch_no" href="#" data-type="text" data-pk="{{ $id }}"
                               data-url="{{ '/xqc/overseas-in/os-dropshipping/'.$id }}"
                               data-value="{{ $delivery->batch_no }}">{{ $delivery->batch_no }}
                            </a>
                        @else
                            {{ $delivery->batch_no }}
                        @endif
                    </td>
                    <td>
                        <a class="grid-editable-remarks" href="#" data-type="textarea" data-pk="{{ $id }}"
                           data-url="{{ '/xqc/overseas-in/os-dropshipping/'.$id }}"
                           data-value="{{ $delivery->remarks }}">{{ $delivery->remarks }}
                        </a>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
@if($delivery->transport->isNotEmpty())
    <div class="box box-solid no-margin box-show">
        <div class="box-body">
            <h4>运输信息</h4>
            <div class="box-body table-responsive no-padding">
                <table class="table">
                    <thead>
                    <tr>
                        <th>状态</th>
                        <th>时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($delivery->transport as $item)
                        <tr>
                            <td>{{ \App\Models\OverSeasIn\DeliveryTransport::$_status[$item->status] }}</td>
                            <td>{{ $item->date_at ?? '--' }}</td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endif
<div class="box box-solid no-margin box-show">
    <div class="box-body">
        <h4>产品信息</h4>
        <div class="box-body table-responsive no-padding">
            <table class="table">
                <thead>
                <tr>
                    <th>SKU总数</th>
                    <th>产品总件数</th>
                    <th>实发总件数</th>
                    <th>发货箱数</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>{{ $delivery->total_sku }}</td>
                    <td>{{ $delivery->total_unit }}</td>
                    <td>{{ $delivery->ship_total_unit }}</td>
                    <td>{{ $delivery->total_box }}</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="box box-solid no-margin box-show">
    <div class="box-body">
        <h4>仓库信息</h4>
        <div class="box-body table-responsive no-padding">
            <table class="table">
                <thead>
                <tr>
                    <th>仓库</th>
                    <th>入库代码</th>
                    <th>国家</th>
                    <th width="15%">地址</th>
                    <th>邮编</th>
                    <th>联系人</th>
                    <th>电话</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>{{ $delivery->warehouse->w_code ?? '' }}</td>
                    <td>{{ $delivery->warehouse->in_code ?? '' }}</td>
                    <td>{{ $delivery->warehouse->country->country ?? '' }}</td>
                    <td>{{ $delivery->warehouse->address ?? '' }}</td>
                    <td>{{ $delivery->warehouse->postcode ?? '' }}</td>
                    <td>{{ $delivery->warehouse->contact ?? '' }}</td>
                    <td>{{ $delivery->warehouse->phone ?? '' }}</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="box box-solid no-margin box-show">
    <div class="box-body">
        <h4>物流信息</h4>
        <div class="box-body table-responsive no-padding">
            <table class="table">
                <thead>
                <tr>
                    <th>物流公司</th>
                    <th>物流渠道</th>
                    <th>追踪号</th>
                    <th>发货公斤数</th>
                    <th>运费</th>
                    <th>到货日期</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>{{ \App\Models\Basics\ExpressCompany::getNameById($delivery->logistics->express_company_id ?? null) }}</td>
                    <td>{{ \App\Models\Basics\ExpressChannel::getNameById($delivery->logistics->express_channel_id ?? null) }}</td>
                    <td>{{ $delivery->logistics->tracking_no ?? '' }}</td>
                    <td>{{ $delivery->logistics->total_weight ?? '' }}</td>
                    <td>{{ $delivery->logistics->shipping_fee ?? '' }}</td>
                    <td>{{ $delivery->logistics->arrived_at ?? '' }}</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script language="JavaScript" type="text/javascript">
    $(function () {
        var editableRefresh = function (name,refresh = true) {
            if(refresh){
                $('.grid-editable-'+name).editable({"emptytext":"<i class=\"fa fa-pencil\"><\/i>","showbuttons":false,"mode":"inline","name":name,
                    success: function(response, newValue) {
                        $.pjax.reload("#os-delivery-form");
                        if (typeof response === 'object') {
                            if (response.status) {
                                toastr.success('提交成功 !');
                            } else {
                                swal(response.message, '', 'error');
                            }
                        }
                    }
                });
            }else{
                $('.grid-editable-'+name).editable({"emptytext":"<i class=\"fa fa-pencil\"><\/i>","name":name});
            }
        };
        editableRefresh('remarks',false);
        editableRefresh('batch_no',false);
    });
</script>
